package org.lc.stk.model.question.impl.fillBlank;

import org.hibernate.annotations.Comment;
import org.lc.stk.model.question.QuestionStem;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;

/**
 * 填空题题干
 */
@Entity
@Table(name = "fill_blank_stems")
@Comment("填空题题干")
public class FillBlankQuestionStem extends QuestionStem {
    
    @Lob
    @NotBlank(message = "题干内容不能为空")
    @Column(name = "content")
    @Comment("富文本内容")
    private String body;
    
    @Min(value = 1, message = "填空位数量必须大于0")
    @Column(name = "blank_count")
    @Comment("填空位数量")
    private int blankCount;
    
    public String getBody() {
        return body;
    }
    
    public void setBody(String content) {
        this.body = content;
        if (content != null) {
            this.blankCount = FillBlankStemFormatter.countBlanks(content);
        }
    }
    
    public int getBlankCount() {
        return blankCount;
    }
    
    /**
     * 验证题干格式是否正确
     */
    public boolean validate() {
        return FillBlankStemFormatter.validateBlankFormat(body);
    }
}